package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.domain.CheckItem;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @PackageName: com.itheima.service.impl
 * @ClassName: CheckItemServiceImpl
 * @Author: Solomon
 * @Date: 2020/7/1 10:32
 * @Description:
 */
@Service(interfaceClass = CheckItemService.class)
@Transactional
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;

    //条件分页查询
    @Override
    public PageResult findByPage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();

        PageHelper.startPage(currentPage,pageSize);

        Page<CheckItem> page = checkItemMapper.findByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    //新增检查项
    @Override
    public void add(CheckItem checkItem) {
        checkItemMapper.add(checkItem);
    }

    //根据id查询检查项信息
    @Override
    public CheckItem findByCheckItemId(Integer checkItemId) {
        return checkItemMapper.findByCheckItemId(checkItemId);
    }

    //修改检查项信息
    @Override
    public void update(CheckItem checkItem) {
        checkItemMapper.update(checkItem);
    }

    //根据id在查询当前检查项是否关联检查组
    @Override
    public int findCountByCheckItemId(Integer checkItemId) {
        return checkItemMapper.findCountByCheckItemId(checkItemId);
    }

    //根据id删除检查项
    @Override
    public void delete(Integer checkItemId) {
        checkItemMapper.delete(checkItemId);
    }

    //在新增或编辑检查组时，发送请求查询所有的检查项
    @Override
    public List<CheckItem> findAll() {
        return checkItemMapper.findAll();
    }
}
